<template>
  <div>
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="90" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <div class="box">
      关爱对象信息
      <FilterTable
        ref="table"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        :height="'auto'"
        :isSelectColumn="false"
        :isToperInfo="false"
        columnsRef="ysjSales2019092501Table"
        :onColumnsChange="columns => (this.columns = columns)"
      >
      </FilterTable>
    </div>

    <Drawer
      :visible.sync="visible"
      :title="type == 'add' ? '关爱' : '关爱明细'"
      :width="1200"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <SalesVisitDetail :type="type" :recordVersion="recordVersion" :careTargetId="careTargetId" :employeeId="employeeId" :billId="id" @changeHandle="changeHandle" @close="closeHandler" />
    </Drawer>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { formatdate } from '@/utils/index';
import { getCareObjList } from '@/api/customerRepair/visitRules/preSales2';
import SalesVisitDetail from '../salesVisit2/salesVisitDetail';

export default {
  name: 'preSales',
  components: { SalesVisitDetail },
  mixins: [dictionary],
  data() {
    return {
      columns: this.createTableColumns(),
      topFilterList: this.createTopFilters(),
      fetchApi: getCareObjList,
      fetchParams: {},
      type: '',
      visible: false,
      recordVersion: '',
      careTargetId: '',
      employeeId: '',
      id: ''
    };
  },
  methods: {
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          label: '客户编号',
          fieldName: 'customerNo',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '请输入...'
        },
        {
          type: 'INPUT',
          label: '联系手机',
          fieldName: 'phone2',
          placeholder: '请输入...'
        },
        {
          type: 'SELECT',
          label: '客户来源',
          fieldName: 'field1',
          placeholder: '请选择...',
          itemList: this.createDictList('1592')
        },
        {
          type: 'SELECT',
          label: '关爱状态',
          fieldName: 'careStatusList',
          placeholder: '请选择...',
          itemList: this.createDictList('1592')
        },
        {
          type: 'SELECT',
          label: '关爱人员',
          fieldName: 'careEmpId',
          placeholder: '请选择...',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '关爱名称',
          fieldName: 'name',
          placeholder: '请输入关爱名称'
        },
        {
          type: 'RANGE_DATE',
          label: '要求完成日期',
          fieldName: 'requiredDateStart|requiredDateEnd',
          placeholder: '要求完成日期'
        },
        {
          type: 'RANGE_DATE',
          label: '建档日期',
          fieldName: 'stockInOutDateStart|stockInOutDateEnd',
          placeholder: '建档日期'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          align: 'center',
          width: 70,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 115,
          fixed: 'left',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.careTask(props.row)}>
                  关爱
                </el-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text" onClick={() => this.careTaskDetail(props.row)}>
                  关爱明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '关爱人员',
          dataIndex: 'careEmpName',
          filterType: 'input'
        },
        {
          title: '客户编号',
          dataIndex: 'customerNo',
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          filterType: 'input'
        },
        {
          title: '性别',
          dataIndex: 'gender',
          filterType: 'input',
          render: props => {
            return <div>{this.createDictText(props.row.gender, '1002')}</div>;
          }
        },
        {
          title: '销售顾问',
          dataIndex: 'consultant',
          filterType: 'input'
        },
        {
          title: '联系人手机',
          dataIndex: 'mobilePhone',
          filterType: 'input'
        },
        {
          title: '联系人电话',
          dataIndex: 'phone',
          filterType: 'input'
        },
        {
          title: '要求完成日期',
          dataIndex: 'requiredDate',
          filterType: 'input',
          render: props => {
            if (props.row.requiredDate && props.row.requiredDate != '') {
              return <div>{formatdate(new Date(parseInt(props.row.requiredDate)), 1)}</div>;
            }
          }
        },
        {
          title: '下次关爱日期',
          dataIndex: 'nextCareDate',
          filterType: 'input',
          render: props => {
            if (props.row.nextCareDate && props.row.nextCareDate != '') {
              return <div>{formatdate(new Date(parseInt(props.row.nextCareDate)), 1)}</div>;
            }
          }
        },
        {
          title: '关爱状态',
          dataIndex: 'careStatus',
          filterType: 'input',
          render: props => {
            return <div>{this.createDictText(props.row.careStatus, '1592')}</div>;
          }
        },
        {
          title: '任务编号',
          dataIndex: 'taskNo',
          filterType: 'input',
          width: 125
        },
        {
          title: '品牌',
          dataIndex: 'brandName',
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'seriesName',
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'modelName',
          filterType: 'input'
        },
        {
          title: '总体满意度',
          dataIndex: 'satisfaction',
          filterType: 'input'
        },
        {
          title: '关爱内容',
          dataIndex: 'careContent',
          filterType: 'input'
        }
      ];
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    closeHandler() {
      this.visible = false;
    },
    careTask(row) {
      this.type = 'add';
      this.visible = true;
      this.id = row.billId + '';
      this.employeeId = row.careEmpId + '';
      this.careTargetId = row.careTargetId + '';
    },
    careTaskDetail(row) {
      this.type = 'show';
      this.visible = true;
      this.id = row.billId + '';
      this.employeeId = row.careEmpId + '';
      this.careTargetId = row.careTargetId + '';
    }
  }
};
</script>
